/*   time:2019-06-13 20:39:25*/
var t = getApp(),
    i = t.requirejs("/core"),
    a = t.requirejs("foxui");
t.requirejs("jquery"), Page({
    data: {
        activity_setting: {},
        shareid: "",
        id: "",
        share_id: "",
        time: ["00", "00", "00", "00"],
        listlength: !1,
        pindex: 6
    },
    onLoad: function(i) {
        t.url(i);
        var a = this;
        i.share_id && a.setData({
            share_id: i.share_id
        }), i.id && a.setData({
            id: i.id
        }), a.getList()
    },
    getCoupon: function(e) {
        var r = this;
        if (!r.data.isGet) {
            var s = {
                id: r.data.id,
                share_id: r.data.share_id,
                form_id: e.detail.formId
            };
            r.data.isLogin ? (r.setData({
                isGet: !0
            }), i.get("friendcoupon/receive", s, function(t) {
                0 == t.error ? (a.toast(r, "领取成功"), r.getList(), r.setData({
                    isGet: !1
                })) : r.setData({
                    invalidMessage: t.message.replace("<br>", "\n"),
                    isGet: !1
                })
            })) : t.checkAuth()
        }
    },
    carve: function(e) {
        var r = this,
            s = {
                id: r.data.id,
                share_id: r.data.share_id,
                form_id: e.detail.formId
            };
        r.data.isLogin ? i.get("friendcoupon/divide", s, function(t) {
            t.error, a.toast(r, t.message), r.getList()
        }) : t.checkAuth()
    },
    mycoupon: function() {
        this.setData({
            id: this.data.data.currentActivityInfo.activity_id,
            share_id: this.data.data.currentActivityInfo.headerid
        }), this.getList()
    },
    onShareAppMessage: function(t) {
        var a = this,
            e = a.data.data.activitySetting.title,
            r = "/friendcoupon/index?share_id=" + a.data.shareid + "&id=" + a.data.id;
        return i.onShareAppMessage(r, e)
    },
    more: function() {
        var e = this,
            r = e.data.activityList;
        i.get("friendcoupon/more", {
            id: e.data.id,
            share_id: e.data.shareid,
            pindex: e.data.pindex
        }, function(t) {
            0 === t.result.list.length ? a.toast(e, "没有更多了") : e.setData({
                activityList: r.concat(t.result.list),
                pindex: e.data.pindex + 10
            })
        })
    },
    getList: function() {
        var r = this;
        i.get("friendcoupon", {
            id: r.data.id,
            share_id: r.data.share_id
        }, function(t) {
            if (0 == t.error) {
                if (t.currentActivityInfo && (t.currentActivityInfo.enough = Number(t.currentActivityInfo.enough)), "string" == typeof t.activitySetting.desc && r.setData({
                    isArray: !0
                }), r.setData({
                    activityData: t.activityData,
                    activityList: 5 < t.activityData.length ? t.activityData.slice(0, 5) : t.activityData,
                    data: t,
                    isLogin: t.isLogin,
                    mylink: t.mylink,
                    invalidMessage: t.invalidMessage,
                    shareid: t.currentActivityInfo ? t.currentActivityInfo.headerid : ""
                }), +t.overTime + 3 > Math.round(+new Date / 1e3)) var e = setInterval(function() {
                    r.setData({
                        time: i.countDown(+t.overTime + 3)
                    }), r.data.time || (clearInterval(e), r.getList())
                }, 1e3)
            } else a.toast(r, t.message)
        })
    }
});